﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MvvmKitDemo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var box = new CustomTextBox();
            box.IsHightLighted= true;
        }
    }


    public class CustomTextBox : TextBox
    {
        #region IsHightLighted

        public bool IsHightLighted
        {
            get { return (bool)GetValue(IsHightLightedProperty); }
            set { SetValue(IsHightLightedProperty, value); }
        }
        public static readonly DependencyProperty IsHightLightedProperty =
            DependencyProperty.Register(
                nameof(IsHightLighted),
                typeof(bool),
                typeof(CustomTextBox),
                new PropertyMetadata(false,Callback));

        private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var box = d as CustomTextBox;
            box.Background = Brushes.Green;
            //box.TextChanged +=  Action  ;
        }

        #endregion

        #region HasText
        public bool HasText => (bool)GetValue(HasTextProperty);

        public static readonly DependencyProperty HasTextProperty;
        public static readonly DependencyPropertyKey HasTextPropertyKey;
        
        static CustomTextBox()
        { 
            HasTextPropertyKey = DependencyProperty.RegisterReadOnly(
                nameof(HasText),
                typeof(bool), 
                typeof(CustomTextBox),
                new PropertyMetadata(false));
            HasTextProperty = HasTextPropertyKey.DependencyProperty;
        }
         
        #endregion



    }

    public class TextBoxHelper
    { 

        public static string GetTitle(DependencyObject obj)
        {
            return (string)obj.GetValue(TitleProperty);
        }

        public static void SetTitle(DependencyObject obj, string value)
        {
            obj.SetValue(TitleProperty, value);
        }

        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.RegisterAttached(
                "Title", 
                typeof(string), 
                typeof(TextBoxHelper),
                new PropertyMetadata("default"));

         
    }


}
